<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Models\AdminUser;
use Cache;
use App\Jobs\WeekCheckoutJob;

class WeekCheckoutCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'command:weekcheckout';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '周结账';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {

        \Log::channel('week_checkouts')->info('记录周结算：'.date('Y-m-d H:i:s'));
        $user = AdminUser::whereHas('roles', function ($q) {
            $q->where('id', '2');
        })->get();

        if ($user) {
            foreach ($user as $k => $v) {
                dispatch(new WeekCheckoutJob($v));
            }
        }
    }
}
